/*
 * EvolutiveCaseGeneratorBuilder.cpp
 *
 *  Created on: 29/05/2011
 *      Author: godinho
 */

#include <evolutive/EvolutiveCaseGeneratorBuilder.h>
#include <evolutive/impl/RouletteWheelSelector.h>
#include <evolutive/impl/MesoscopicTrafficSimulation.h>
#include <evolutive/impl/NakamitFitnessFunction.h>
#include <evolutive/OffspringGenerator.h>

EvolutiveCaseGeneratorBuilder::EvolutiveCaseGeneratorBuilder() {
	mEventListener = 0;
}

EvolutiveCaseGeneratorBuilder::~EvolutiveCaseGeneratorBuilder() {
}

EvolutiveCaseGenerator* EvolutiveCaseGeneratorBuilder::buildEvolutiveCaseGenerator() {
	EvolutiveCaseGenerator* evolutiveCaseGenerator = new EvolutiveCaseGenerator();

	evolutiveCaseGenerator->setCaseSelector(buildCaseSelector());
	evolutiveCaseGenerator->setLifeSimulator(buildLifeSimulator());
	evolutiveCaseGenerator->setFitnessFunction(buildFitnessFunction());
	evolutiveCaseGenerator->setOffspringGenerator(buildOffspringGenerator());
	evolutiveCaseGenerator->setEventListener(mEventListener);

	return evolutiveCaseGenerator;
}

CaseSelector* EvolutiveCaseGeneratorBuilder::buildCaseSelector() {
	CaseSelector* selector = new RouletteWheelSelector();
	return selector;
}

LifeSimulator* EvolutiveCaseGeneratorBuilder::buildLifeSimulator() {
	MesoscopicTrafficSimulation* simulator = new MesoscopicTrafficSimulation();
	return simulator;
}

FitnessFunction* EvolutiveCaseGeneratorBuilder::buildFitnessFunction() {
	NakamitFitnessFunction* fitness = new NakamitFitnessFunction();
	return fitness;
}

OffspringGenerator* EvolutiveCaseGeneratorBuilder::buildOffspringGenerator() {
	OffspringGenerator* generator = new OffspringGenerator();

	generator->setEventListener(mEventListener);

	return generator;
}

void EvolutiveCaseGeneratorBuilder::setEventListener(EventListener* listener) {
	mEventListener = listener;
}
